﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ComicReader.Model;
using ComicReader.Views;

namespace ComicReader.Controllers
{
    internal class ReaderPageController
    {
        private readonly ReaderPage ReaderPage;
        private readonly IPageDataService PageDataService;


        public ReaderPageController(ReaderPage page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            ReaderPage = page;
            PageDataService = new PageDataService();

            OpenArchive();
        }

        public void OpenArchive()
        {
            var dialog = new OpenFileDialog
            {
                Multiselect = false,
                Filter = "Cbz|*.cbz|Zip|*.zip|All Files|*.*"
            };

            if (dialog.ShowDialog() != DialogResult.OK) return;

            var fileInfo = new FileInfo(dialog.FileName);
            PageDataService.Load(fileInfo);

            ReaderPage.ArchiveList.ItemsSource = PageDataService.List();
            if (ReaderPage.ArchiveList.Items.Count > 0)
            {
                ReaderPage.ArchiveList.SelectedIndex = 0;
            }


        }
    }
}
